const util = require('../../../../../../../utils/util.js');
const api = require('../../../../../../../config/api.js');
const recorderManager = wx.getRecorderManager();
var recordInterval = null;

//获取应用实例
const app = getApp()
const openid = app.globalData.logininfo.openid; 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeid: "",// 主题id
    zsDialogAs: false,// 控制鼓励赞赏弹窗的文字
    zsDialogShow: false,// 控制鼓励赞赏的弹窗
    diaryVideoCount: 0,// 视频数量
    addressOauhRefusedDialogShow: false,// 地理位置拒绝授权的弹窗
    audioOauhRefusedDialogShow: false,// 语音拒绝授权的弹窗
    isOpenDiaShow: false,
    videoPopupShow: false,// 选择视频的弹出层
    imagePopupShow: false,// 选择图片的弹出层
    linkNameDialogShow: false,// 显示公众号的链接标题的弹出层
    diaryType: "1", // 打卡类型：1无主题打卡
    isFillclock: "0", //是否是补打卡：0否  1是
    deletetype: "",// 日记删除的类型
    voiceDialogDeleteShow: false,// 删除日记的dialog是否显示
    voiceDialogShow: false,// 录音音频的dialog是否显示
    albumInfo: [],// 圈子【图片、文字、音频】详情信息
    ordInterest: {},// 圈子详情
    mainUser: {}, // 圈主信息
    circleid: "",// 圈子id
    ordInterestJoinCount: 0,// 参与数量
    diaryCount: 0,// 日记数量
    isShowCenter: false,
    announcementShow: false, // 公告栏是否显示
    announcementTextareaDisabled: true,
    openid: openid, // 当前用户id
    nickName: "", // 当前用户昵称
    diaryText: {},// 文字
    diaryVideoAndImage: [],// 视频和图片
    diaryVideoAndImageMaxSize: 9,// 视频和图片最大数量
    diaryAudio: {},// 音频
    diaryLink: {},// 链接
    diaryPosition: {},// 位置
    diaryAppreciate: {},// 赞赏
    diaryPopupShow: false,// 隐私底部是否弹出
    isprivate: '0',// 是否隐私状态：0：公开、1：仅对圈主可见
    isSumbitType: false, // 是否为提交状态：控制提交多次
    diaryPositionCurrent: {},// 当前位置
    linkErrorDialogShow: false,// 链接错误时的弹出
    linkPopupShow: false,// 链接底部的选择弹出
    themeInfo: {},//主题信息
    themeDataList: [],//主题数据
    isCheckCompleteByDiary: true,// 是否可以查看完整的主题信息
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this;
    var circleid = options.circleid;
    var themeid = options.themeid;
    _this.setData({
      circleid: circleid,
      nickName: app.globalData.logininfo.userInfo.nickName,
      themeid: themeid
    })
    _this.getCircleDetails();
    _this.getcurrentLocation();
    if(themeid != null && String(themeid).length > 0){
      _this.getThemeInfoBySelect();
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 获取圈子信息
   */
  getCircleDetails: function () {
    var _this = this;
    var circleid = _this.data.circleid;
    var data = {};
    data.circleid = circleid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.getCircleDetailsQuery(api.Home_GetCircleDetailsApiUrl, data);
      })
    } else {
      _this.getCircleDetailsQuery(api.Home_GetCircleDetailsUrl, data);
    }
  },
  
  /**
   * 获取圈子信息：请求
   */
  getCircleDetailsQuery: function (url, data) {
    var _this = this;
    util.post(url, data).then(function (res) {
      if (res.code == 200) {
        var json = res.result.json;
        var mainUser = json.mainUser;
        if (json != null) {
          _this.setData({
            albumInfo: json.albumInfo,
            ordInterest: json.ordInterest,
            ordInterestJoinCount: json.ordInterestJoinCount,
            diaryCount: json.diaryCount,
            mainUser: json.mainUser
          })
        }
      }
    });
  },

  /**
   * 展开或收起圈子详情
   */
  showCenter: function(){
    var _this = this;
    var themeid = _this.data.themeid;
    if (themeid != null && String(themeid).length > 0){
      var isCheckCompleteByDiary = _this.data.isCheckCompleteByDiary;
      if (!isCheckCompleteByDiary){
        return;
      }
    }
    _this.setData({
      isShowCenter: !_this.data.isShowCenter
    })
  },

  /**
   * 公告栏的日记
   */
  announcementDditor: function () {
    var _this = this;
    _this.setData({
      announcementTextareaDisabled: false
    })
  },

  /**
   * 公告栏的确定
   */
  announcementCommit: function () {
    var _this = this;
    var circleNotice = _this.data.ordInterest.circleNotice;
    var announcementTextareaDisabled = _this.data.announcementTextareaDisabled;
    if (circleNotice != null && announcementTextareaDisabled == false) {
      if (openid != null && openid != "") {
        wx.showLoading({
          title: "提交中"
        })
        // 已登录
        util.post(api.fetchToken()).then(function (res) {
          if (res.access_token != '') {
            return Promise.resolve({
              access_token: res.access_token
            });
          }
        }).then(function (res) {
          var data = {};
          data.openid = openid;
          data.access_token = res.access_token;
          data.circleid = _this.data.circleid;
          data.circleNotice = circleNotice;
          util.post(api.Home_UpdateCircleNoticeApiUrl, data).then(function (res) {
            wx.hideLoading();
            if (res.code == 200) {
              var pages = getCurrentPages();
              var prevPage = pages[pages.length - 2];  //上一个页面
              prevPage.setData({
                ["ordInterest.circleNotice"]: circleNotice
              });
              util.post(api.Home_UpdateCircleNoticeByJoinApiUrl, data).then(function (res) { });
            }
          });
        })
      } else {
        util.dialogAlert("未进行登录");
      }
    }
    _this.setData({
      announcementShow: false,
      isOpenDiaShow: false,
      announcementTextareaDisabled: true,
      ["ordInterest.circleNotice"]: circleNotice
    })
  },

  /**
   * 公告栏的texteare输入事件
   */
  circleNoticeInput: function (e) {
    var _this = this;
    var circleNotice = e.detail.value;
    _this.setData({
      ["ordInterest.circleNotice"]: circleNotice
    })
  },

  /**
   * 公告栏的弹出
   */
  announcementTap: function () {
    var _this = this;
    _this.setData({
      announcementShow: !_this.data.announcementShow,
      isOpenDiaShow: !_this.data.announcementShow
    })
  },

  /**
   * 日记专辑详情
   */
  editorAlbumInfo: function (e) {
    var _this = this;
    var type = e.currentTarget.dataset.type; 
    switch (type) {
      case "1":
        // 文字
        var diaryText = _this.data.diaryText;
        diaryText.focus = true;
        diaryText.value = "";
        diaryText.isShow = true;
        diaryText.autoheight = true;
        _this.setData({
          diaryText: diaryText
        })
        break; 
      case "2":
        // 图片
        _this.setData({
          imagePopupShow: true,
          isOpenDiaShow: true
        })
        break;
      case "3":
        // 音频
        wx.getSetting({
          success(res) {
            if (!res.authSetting['scope.record']) {
              // 未授权
              wx.authorize({
                scope: 'scope.record',
                success() {
                  _this.recorderStart();
                },
                fail: function () {
                  // 拒绝授权
                  _this.setData({
                    audioOauhRefusedDialogShow: true
                  })
                }
              })
            }else{
              // 已授权
              _this.recorderStart();
            }
          }
        })
        break;
      case "4":
        // 视频
        _this.setData({
          videoPopupShow: true,
          isOpenDiaShow: true
        })
        break;
      case "5":
        // 链接
        _this.setData({
          linkPopupShow: true,
          isOpenDiaShow: true
        })
        break;
      case "6":
        // 位置
        wx.getSetting({
          success(res) {
            console.log(res.authSetting)
            if (!res.authSetting['scope.userLocation']) {
              // 未授权
              wx.authorize({
                scope: 'scope.userLocation',
                success() {
                  _this.diaryPositionStart();
                },
                fail: function () {
                  // 拒绝授权
                  _this.setData({
                    addressOauhRefusedDialogShow: true
                  })
                }
              })
            }else{
              // 已授权
              _this.diaryPositionStart();
            }
          }
        })
        break;
      case "7":
        // 赞赏
        var diaryAppreciate = {};
        diaryAppreciate.isShow = true;
        _this.setData({
          diaryAppreciate: diaryAppreciate,
          zsDialogAs: true
        })
        _this.zsDialogShow();
        break;
      case "8":
        // 隐私
        _this.setData({
          diaryPopupShow: true,
          isOpenDiaShow: true
        })
        break;
    }
  },

  /**
   * 位置
   */
  diaryPositionStart: function(){
    var _this = this;
    wx.chooseLocation({
      success: function (res) {
        var diaryPosition = _this.data.diaryPosition;
        var name = res.name;
        var latitude = res.latitude;
        var longitude = res.longitude;
        var address = res.address;
        if(name.length > 0){
          diaryPosition.value = name;
          diaryPosition.latitude = latitude;
          diaryPosition.longitude = longitude;
          diaryPosition.address = address;
          diaryPosition.isShow = true;
          _this.setData({
            diaryPosition: diaryPosition
          })
        }
      }
    })
  },

  /**
   * 开始录音
   */
  recorderStart: function(){
    var _this = this;
    const recorderOptions = {
      duration: util.getAudioFileMaxTime("diary"),//指定录音的时长，单位 ms
      format: 'mp3'
    }
    var diaryAudio = _this.data.diaryAudio;
    diaryAudio.state = "1";// 1正在录音  2录音完毕（state==2的时候，playState无效）
    diaryAudio.playState = "1";// 1正常录音  2暂停录音
    diaryAudio.totalTime = 0;
    diaryAudio.totalDate = "00:00";
    diaryAudio.isVoiceDialogShow = true;
    diaryAudio.isShow = true;
    _this.setData({
      diaryAudio: diaryAudio
    })

    //开始录音
    recorderManager.start(recorderOptions);

    // 定时器计算录音时间
    _this.doRecordInterval();

    // 录音结束
    recorderManager.onStop((res) => {
      _this.stopRecorderExecute(res);
    });

    // 录音中断
    recorderManager.onInterruptionBegin((res) => {
      recorderManager.stop();
      _this.setData({
        ["diaryAudio.isVoiceDialogShow"]: false
      })
      _this.stopRecorderExecute(res);
    });
  },

  /**
   * 日记详情文字的焦点移出事件
   */
  albumInfoTextareaInput: function (e) {
    var _this = this;
    var value = e.detail.value;
    _this.setData({
      ["diaryText.value"]: value
    })
  },

  /**
   * 日记详情文字的焦点移出事件
   */
  albumInfoTextareaBlur: function (e) {
    var _this = this;
    var isSwitchEmoji = false;
    if (e.detail != null && e.detail.isSwitchEmoji != null) {
      isSwitchEmoji = e.detail.isSwitchEmoji;
    }
    if (!isSwitchEmoji){
      _this.setData({
        ["diaryText.focus"]: false,
        ["diaryText.autoheight"]: false
      })
    }
  },

/**
   * 日记详情文字的聚焦事件
   */
  albumInfoTextareaFocus: function(e){
    var _this = this;
    _this.setData({
      ["diaryText.focus"]: true,
      ["diaryText.autoheight"]: true
    })
  },

  /**
   * 清除定时器
   */
  doClearInterval: function () {
    clearInterval(recordInterval);
    recordInterval = null;
  },

  /**
   * 定时器计算录音时间
   */
  doRecordInterval: function () {
    var _this = this;
    if (recordInterval == null){
      recordInterval = setInterval(function () {
        var diaryAudio = _this.data.diaryAudio;
        var totalTime = diaryAudio.totalTime + 1;
        var totalDate = util.digitalFormatTime(totalTime);
        _this.setData({
          ["diaryAudio.totalTime"]: totalTime,
          ["diaryAudio.totalDate"]: totalDate
        });
      }, 1000);
    }
  },

  /**
   * 暂停录音
   */
  pauseRecorder: function (e) {
    var _this = this;
    _this.setData({
      ["diaryAudio.playState"]: "2"
    });
    recorderManager.pause();
    _this.doClearInterval();
  },

  /**
   * 继续录音
   */
  resumeRecorder: function (e) {
    var _this = this;
    _this.setData({
      ["diaryAudio.playState"]: "1"
    })
    recorderManager.resume();
    _this.doRecordInterval();
  },

  /**
   * 停止录音
   */
  stopRecorder: function (e) {
    var _this = this;
    recorderManager.stop();
    recorderManager.onStop((res) => {
      _this.stopRecorderExecute(res);
    });
  },

  /**
   * 停止录音后的业务代码
   */
  stopRecorderExecute: function (tempFile) {
    var _this = this;
    _this.doClearInterval();
    var isVoiceDialogShow = _this.data.diaryAudio.isVoiceDialogShow;
    if (isVoiceDialogShow) {
      var totalTime = parseInt(tempFile.duration / 1000);
      var diaryAudio = _this.data.diaryAudio;
      diaryAudio.state = "2";
      diaryAudio.src = tempFile.tempFilePath;
      diaryAudio.title = "";
      diaryAudio.currentTime = 0;
      diaryAudio.totalTime = totalTime;
      diaryAudio.fileSize = tempFile.fileSize;
      diaryAudio.startDate = "00:00";
      diaryAudio.totalDate = util.digitalFormatTime(totalTime);
      diaryAudio.voiceBoFangImage = api.AudioNoBoFangImage_Name;
      _this.setData({
        diaryAudio: diaryAudio
      })
      _this.voiceDialogShow();
    }
  },
  
  
  /**
   * 是否展示音频dialog
   */
  voiceDialogShow: function (e) {
    var _this = this;
    var voiceDialogShow = _this.data.voiceDialogShow;
    if (voiceDialogShow) {
      // 关闭
      var title = _this.data.diaryAudio.title;
      if (title.trim().length <= 0){
        title = _this.data.nickName + "的音频"
      }
      _this.setData({
        voiceDialogShow: false,
        isOpenDiaShow: false,
        ["diaryAudio.title"]: title
      })
    } else {
      // 开启
      _this.setData({
        voiceDialogShow: true,
        isOpenDiaShow: true
      })
    }
  },

  /**
   * 录音音频名称的修改
   */
  voiceUpdateTitle: function (e) {
    var _this = this;
    var title = e.detail;
    _this.setData({
      ["diaryAudio.title"]: title
    })
  },

  /**
   * 播放或暂停动作：圈子详情的
   */
  voiceBoFang_info: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var albumInfo = _this.data.albumInfo;
    var boFangImage = albumInfo[index].boFangImage;
    var ip = albumInfo[index].ip;
    var name = albumInfo[index].name;
    var currentTime = albumInfo[index].currentTime;
    var audiourl = albumInfo[index].audiourl;
    var backgroundAudioManager = wx.getBackgroundAudioManager();//获取全局唯一的背景音频管理器
    if (boFangImage == api.AudioBoFangImage_Name) {
      // 切换至暂停状态
      wx.pauseBackgroundAudio();//暂停播放音乐
      backgroundAudioManager.pause();//暂停播放音乐
      _this.setData({
        ["albumInfo[" + index + "].boFangImage"]: api.AudioNoBoFangImage_Name
      });
    } else {
      // 切换至播放状态
      wx.stopBackgroundAudio();////暂停正在播放音乐
      backgroundAudioManager.startTime = currentTime;//设置音乐开始时间
      backgroundAudioManager.title = name;
      backgroundAudioManager.src = ip + audiourl;
      backgroundAudioManager.play();
      //    背景音频自然播放结束事件
      backgroundAudioManager.onEnded(function () {
        _this.setData({
          ["albumInfo[" + index + "].startDate"]: "00:00",
          ["albumInfo[" + index + "].currentTime"]: 0,
          ["albumInfo[" + index + "].boFangImage"]: api.AudioNoBoFangImage_Name
        });
      })
      //背景音频播放进度更新事件
      backgroundAudioManager.onTimeUpdate(function (callback) {
        var position = parseInt(backgroundAudioManager.currentTime);
        var startDate = util.digitalFormatTime(position);
        _this.setData({
          ["albumInfo[" + index + "].currentTime"]: backgroundAudioManager.currentTime,
          ["albumInfo[" + index + "].startDate"]: startDate
        });
      })
      _this.setData({
        ["albumInfo[" + index + "].boFangImage"]: api.AudioBoFangImage_Name
      });
    }
  },

  /**
   * 播放音乐（滚动条事件）：圈子详情
   */
  voiceSlider_info: function (e) {
    var _this = this;
    var position = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var albumInfo = _this.data.albumInfo;
    var boFangImage = albumInfo[index].boFangImage;
    var startDate = util.digitalFormatTime(position);
    var backgroundAudioManager = wx.getBackgroundAudioManager();//获取全局唯一的背景音频管理器
    if (boFangImage == api.AudioBoFangImage_Name) {
      //正在播放状态：不知道为什么，录音的在调用backgroundAudioManager.seek(Math.floor(position))方法无效，所以改成一下这种方式
      _this.setData({
        ["albumInfo[" + index + "].currentTime"]: position,
        ["albumInfo[" + index + "].boFangImage"]: api.AudioNoBoFangImage_Name
      });
      _this.voiceBoFang_info(e);
    } else {
      // 未播放状态
      _this.setData({
        ["albumInfo[" + index + "].currentTime"]: position,
        ["albumInfo[" + index + "].startDate"]: startDate
      });
      console.log(_this.data.albumInfo[index].currentTime);
    }
  },

  /**
   * 播放或暂停动作：日记详情
   */
  voiceBoFang: function (e) {
    var _this = this;
    var src = e.currentTarget.dataset.src;
    var index = e.currentTarget.dataset.index;
    var title = e.currentTarget.dataset.title;
    var currentTime = e.currentTarget.dataset.currenttime;
    var voiceBoFangImage = e.currentTarget.dataset.voiceimage;
    var backgroundAudioManager = wx.getBackgroundAudioManager();//获取全局唯一的背景音频管理器
    if (voiceBoFangImage == api.AudioBoFangImage_Name) {
      // 切换至暂停状态
      backgroundAudioManager.pause();//暂停播放音乐
      _this.setData({
        ["diaryAudio.voiceBoFangImage"]: api.AudioNoBoFangImage_Name
      });
    } else {
      // 切换至播放状态
      wx.stopBackgroundAudio();//暂停正在播放音乐
      backgroundAudioManager.startTime = currentTime;//设置音乐开始时间
      backgroundAudioManager.title = title;
      backgroundAudioManager.src = src;
      backgroundAudioManager.play();
      //    背景音频自然播放结束事件
      backgroundAudioManager.onEnded(function () {
        _this.setData({
          ["diaryAudio.currentTime"]: 0,
          ["diaryAudio.voiceBoFangImage"]: api.AudioNoBoFangImage_Name,
          ["diaryAudio.startDate"]: "00:00"
        });
      })
      //背景音频播放进度更新事件
      backgroundAudioManager.onTimeUpdate(function (callback) {
        var position = Math.round(backgroundAudioManager.currentTime);
        var voiceStartDate = util.digitalFormatTime(position);
        _this.setData({
          ["diaryAudio.currentTime"]: backgroundAudioManager.currentTime,
          ["diaryAudio.startDate"]: voiceStartDate
        });
      })

      _this.setData({
        ["diaryAudio.voiceBoFangImage"]: api.AudioBoFangImage_Name
      });
    }
  },

  /**
   * 播放音乐（滚动条事件）：日记详情
   */
  voiceSlider: function (e) {
    var _this = this;
    var position = e.detail.value;
    var src = e.currentTarget.dataset.src;
    var index = e.currentTarget.dataset.index;
    var title = e.currentTarget.dataset.title;
    var currentTime = e.currentTarget.dataset.currenttime;
    var voiceBoFangImage = e.currentTarget.dataset.voiceimage;
    var voiceStartDate = util.digitalFormatTime(position);
    var backgroundAudioManager = wx.getBackgroundAudioManager();//获取全局唯一的背景音频管理器
    if (voiceBoFangImage == api.AudioBoFangImage_Name) {
      //正在播放状态：不知道为什么，录音的在调用backgroundAudioManager.seek(Math.floor(position))方法无效，所以改成一下这种方式
      e.currentTarget.dataset.currenttime = position;
      e.currentTarget.dataset.voiceimage = api.AudioNoBoFangImage_Name;
      _this.voiceBoFang(e);
    } else {
      // 未播放状态
      _this.setData({
        ["diaryAudio.currentTime"]: position,
        ["diaryAudio.startDate"]: voiceStartDate
      });
    }
  },

  /**
   * 视频播放
   */
  videoPlay: function (e) {
    var _this = this;
    var videoId = e.currentTarget.dataset.id;
    _this.videoContext = wx.createVideoContext(videoId);
    _this.videoContext.stop();
  },

  /**
   * 链接的焦点移出事件
   */
  albumInfoHrefInput: function (e) {
    var _this = this;
    var value = e.detail.value;
    _this.setData({
      ["diaryLink.name"]: "",
      ["diaryLink.value"]: value,
      ["diaryLink.textareaPlaceholderShow"]: false
    })
    if (value.length <= 0) {
      _this.setData({
        ["diaryLink.textareaPlaceholderShow"]: true
      })
    }
  },

  /**
   * 公众号名称编辑事件
   */
  linkNameInput: function (e) {
    var _this = this;
    var name = e.detail.value;
    _this.setData({
      ["diaryLink.name"]: name
    })
  },

  /**
   * 公众号名称弹窗关闭事件
   */
  linkNameDialogClose: function (e) {
    var _this = this;
    var name = _this.data.diaryLink.name;
    if(name.length <= 0){
      _this.setData({
        ["diaryLink.name"]: "公众号文章"
      })
    }
    _this.setData({
      linkNameDialogShow: false,
      isOpenDiaShow: false,
      ["diaryLink.state"]: "2"
    })
  },

  /**
   * 链接的焦点移出事件
   */
  albumInfoHrefBlur: function (e) {
    var _this = this;
    var value = _this.data.diaryLink.value;
    _this.setData({
      ["diaryLink.focus"]: false
    })
    if (_this.checkLink() && value.length > 0){
      _this.setData({
        linkNameDialogShow: true,
        isOpenDiaShow: true
      })
    }
  },

  /**
   * 删除日记详情:弹出dialog
   */
  deleteDialogShow: function (e) {
    var _this = this;
    var deletetype = e.currentTarget.dataset.type;
    _this.setData({
      deletetype: deletetype,
      voiceDialogDeleteShow: true,
      isOpenDiaShow: true
    })
  },

  /**
   * 清空录音
   */
  clearRecorder: function () {
    var _this = this;
    _this.doClearInterval();
    _this.setData({
      ["diaryAudio.isVoiceDialogShow"]: false
    })
    recorderManager.stop();
    setTimeout(function () {
      // 音频
      wx.getSetting({
        success(res) {
          if (!res.authSetting['scope.record']) {
            // 未授权
            wx.authorize({
              scope: 'scope.record',
              success() {
                _this.recorderStart();
              },
              fail: function () {
                // 拒绝授权
                _this.setData({
                  audioOauhRefusedDialogShow: true
                })
              }
            })
          } else {
            // 已授权
            _this.recorderStart();
          }
        }
      })
    }, 100)
  },

  /**
   * 删除
   */
  deleteDiary: function (e) {
    var _this = this;
    if (e.detail == "confirm") {
      var deletetype = _this.data.deletetype;
      switch (deletetype) {
        case "1":
          // 删除文字
          _this.setData({
            diaryText: {}
          })
          break;
        case "2":
          // 删除图片
          _this.setData({
            diaryVideoAndImage: [],
            diaryVideoCount: 0
          })
          break;
        case "3":
          // 删除音频
          recorderManager.stop();
          _this.setData({
            diaryAudio: {}
          })
          break;
        case "5":
          // 删除链接
          _this.setData({
            diaryLink: {}
          })
          break;
        case "6":
          // 删除位置
          _this.setData({
            diaryPosition: {}
          })
          break;
        case "7":
          // 删除赞赏
          _this.setData({
            diaryAppreciate: {}
          })
          break;
      }
    }
    _this.setData({
      deletetype: "",
      voiceDialogDeleteShow: false,
      isOpenDiaShow: false
    })
  },

  /**
   * 修改隐私状态
   */
  updatePrivate: function (e) {
    var _this = this;
    var isprivate = e.currentTarget.dataset.isprivate;
    _this.setData({
      isprivate: isprivate,
      diaryPopupShow: false,
      isOpenDiaShow: false
    })
  },

  /**
   * 修改隐私状态
   */
  closePrivate: function (e) {
    var _this = this;
    _this.setData({
      diaryPopupShow: false,
      isOpenDiaShow: false
    })
  },

  /**
   * 提交服务器
   */
  submit: function(){
    var _this = this;
    wx.showLoading({
      title: '保存中',
    })
    _this.setData({
      isSumbitType: true
    })
    var diaryAudio = _this.data.diaryAudio;
    var diaryVideoAndImage = _this.data.diaryVideoAndImage;
    var diaryLink = _this.data.diaryLink;
    var uploadInfoList = [];
    // 上传图片和视频
    for (var i = 0; i < diaryVideoAndImage.length; i++) {
      var uploadInfo = {};
      if (diaryVideoAndImage[i].type == "1") {
        uploadInfo.type = "1";// 类型:1图片  2音频  3视频  4链接
      } else {
        uploadInfo.type = "3";// 类型:1图片  2音频  3视频  4链接
      }
      uploadInfo.tempFilesIndex = i;// 编辑详情中的下标
      uploadInfo.filePath = diaryVideoAndImage[i].path;
      uploadInfoList.push(uploadInfo);
    }

    if (diaryAudio.isShow) {
      var uploadInfo = {};
      uploadInfo.type = "2";// 类型:1图片  2音频  3视频  4链接
      uploadInfo.filePath = diaryAudio.src;
      uploadInfoList.push(uploadInfo);
    }

    if (diaryLink.isShow && diaryLink.type == 2){
      var uploadInfo = {};
      uploadInfo.type = "4";// 类型:1图片  2音频  3视频  4链接
      uploadInfo.filePath = diaryLink.value;
      uploadInfoList.push(uploadInfo);
    }
    if (uploadInfoList.length > 0) {
      // 开始请求:要先上传
      _this.uploadFileQuery(uploadInfoList, 0);
    } else {
      _this.saveAlbumInfo();
    }
  },

  /**
   * 上传
   */
  uploadFileQuery: function (data, queryIndex){
    var _this = this;
    var queryData = data[queryIndex];
    var queryUrl = "";
    switch (queryData.type) {
      case "1":
        // 图片
        queryUrl = api.File_doImageUpload;
        break;
      case "2":
        // 音频
        queryUrl = api.File_doAudioUpload;
        break;
      case "3":
        // 视频
        queryUrl = api.File_doVideoUpload;
        break;
      case "4":
        // 链接
        queryUrl = api.File_doOtherUpload;
        break;
    }
    wx.uploadFile({
      url: queryUrl,
      filePath: queryData.filePath,
      name: 'file',
      formData: {
        "type": "3"
      },
      success(res) {
        var data = JSON.parse(res.data);
        if (data.code == 200) {
          var ip = data.result.ip;
          var path = data.result.path;
          switch (queryData.type) {
            case "1":
              // 图片
              var tempFilesIndex = queryData.tempFilesIndex;// 图片里的下标
              _this.setData({
                ["diaryVideoAndImage[" + tempFilesIndex + "].ip"]: ip,
                ["diaryVideoAndImage[" + tempFilesIndex + "].path"]: path
              })
              break;
            case "2":
              // 音频
              _this.setData({
                ["diaryAudio.ip"]: ip,
                ["diaryAudio.src"]: path
              })
              break;
            case "3":
              // 视频
              var ffmpegvideoimagepath = data.result.ffmpegvideoimagepath;
              var tempFilesIndex = queryData.tempFilesIndex;// 图片里的下标
              _this.setData({
                ["diaryVideoAndImage[" + tempFilesIndex + "].ip"]: ip,
                ["diaryVideoAndImage[" + tempFilesIndex + "].path"]: path,
                ["diaryVideoAndImage[" + tempFilesIndex + "].ffmpegvideoimagepath"]: ffmpegvideoimagepath
              })
              if (_this.data.diaryVideoAndImage[tempFilesIndex].totalTime <= 0) {
                var width = data.result.width;
                var height = data.result.height;
                var duration = data.result.duration;
                _this.setData({
                  ["diaryVideoAndImage[" + tempFilesIndex + "].width"]: width,
                  ["diaryVideoAndImage[" + tempFilesIndex + "].height"]: height,
                  ["diaryVideoAndImage[" + tempFilesIndex + "].totalTime"]: duration,
                  ["diaryVideoAndImage[" + tempFilesIndex + "].totalDate"]: util.digitalFormatTime(duration)
                })
              }
              break;
            case "4":
              // 其他
              _this.setData({
                ["diaryLink.ip"]: ip,
                ["diaryLink.value"]: path
              })
              break;
          }
        }
      },
      fail(res) {
        // 失败
      },
      complete(res) {
        // 结束：
        if (queryIndex < data.length - 1) {
          // 图片未上传完成，继续上传
          queryIndex++;
          _this.uploadFileQuery(data, queryIndex);
        } else {
          // 上传完成，执行save请求
          _this.saveAlbumInfo();
        }
      }
    })
  },

  /**
   * save请求
   */
  saveAlbumInfo: function () {
    var _this = this;
    util.post(api.fetchToken()).then(function (res) {
      if (res.access_token != '') {
        return Promise.resolve({
          access_token: res.access_token
        });
      }
    }).then(function (res) {
      var diaryText = _this.data.diaryText;
      var diaryVideoAndImage = _this.data.diaryVideoAndImage;
      var diaryAudio = _this.data.diaryAudio;
      var diaryLink = _this.data.diaryLink;
      var diaryPosition = _this.data.diaryPosition;
      var diaryPositionCurrent = _this.data.diaryPositionCurrent;
      var diaryAppreciate = _this.data.diaryAppreciate;
      var themeid = _this.data.themeid;
      var data = {};
      data.openid = openid;
      data.access_token = res.access_token;
      data.circleid = _this.data.circleid;
      data.diaryType = _this.data.diaryType;
      data.isFillclock = _this.data.isFillclock;
      data.isprivate = _this.data.isprivate;
      if (diaryText.isShow) {
        data.diaryText = JSON.stringify(diaryText);
      }
      if (diaryVideoAndImage.length > 0) {
        data.diaryVideoAndImage = JSON.stringify(diaryVideoAndImage);
      }
      if (diaryAudio.isShow) {
        data.diaryAudio = JSON.stringify(diaryAudio);
      }
      if (diaryLink.isShow) {
        data.diaryLink = JSON.stringify(diaryLink);
      }
      if (diaryPosition.isShow) {
        data.diaryPosition = JSON.stringify(diaryPosition);
      }
      if (diaryPositionCurrent.latitude != null) {
        data.diaryPositionCurrent = JSON.stringify(diaryPositionCurrent);
      }
      if (diaryAppreciate.isShow) {
        data.diaryAppreciate = JSON.stringify(diaryAppreciate);
      }
      if (themeid != null && String(themeid).length > 0) {
        data.themeid = themeid;
      }
      util.post(api.Home_SaveOrUpdateOrdDiaryApiUrl, data).then(function (res) {
        wx.hideLoading();
        _this.setData({
          isSumbitType: false
        })
        if (res.code == 200) {
          var pages = getCurrentPages();
          var prevPage = pages[pages.length - 2];  //上一个页面
          var energyInfoResults = res.result.energyInfoResults;
          if (energyInfoResults){
            prevPage.setData({
              diary_energy_dialog: true,
              jumpDiary: true
            });
          }
          wx.navigateBack({
            delta: 1
          })
        }
      })
    })
  },

  /**
   * 单个图片删除
   */
  deleteDiaryImage: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var diaryVideoAndImage = _this.data.diaryVideoAndImage;
    var type = diaryVideoAndImage[index].type;
    if(type == 2){
      _this.setData({
        diaryVideoCount: 0
      })
    }
    diaryVideoAndImage.splice(index,1);
    _this.setData({
      diaryVideoAndImage: diaryVideoAndImage
    })
  },

  /**
   * 校验链接
   */
  checkLink: function(){
    var _this = this;
    var diaryLink = _this.data.diaryLink;
    var type = diaryLink.type;
    if (diaryLink.isShow && type == 1) {
      var value = diaryLink.value.trim();
      var reg = /^https:\/\/mp.weixin.qq.com*/;
      if (value.length > 0 && !reg.test(value)) {
        _this.setData({
          linkErrorDialogShow: true,
          isOpenDiaShow: true
        })
        return false;
      }
    }
    return true;
  },

  /**
   * 关闭链接错误提示
   */
  linkErrorDialogClose: function(){
    var _this = this;
    _this.setData({
      linkErrorDialogShow: false,
      isOpenDiaShow: false
    })
  },
  
  /**
   * 提交校验
   */
  submitVerify: function () {
    var _this = this;
    var diaryText = _this.data.diaryText;
    var diaryAudio = _this.data.diaryAudio;
    var diaryLink = _this.data.diaryLink;

    if (diaryText.isShow && diaryText.value.trim().length <= 0){
      util.dialogAlert("请填写文字信息");
      return false;
    }

    if (diaryAudio.isShow && diaryAudio.state == "1"){
      util.dialogAlert("未结束录音");
      return false;
    }

    if (diaryLink.isShow) {
      // 链接
      var value = diaryLink.value.trim();
      if (value.length <= 0) {
        util.dialogAlert("请填写链接信息");
        return false;
      }
      if (!_this.checkLink()) {
        return false;
      }
    }
    return true;
  },

  /**
   * 校验主题
   */
  checkUserThemeClock: function(){
    var _this = this;
    if (_this.submitVerify()) {
      var themeid = _this.data.themeid;
      var circleid = _this.data.circleid;
      if(themeid != null && String(themeid).length > 0){
        // 需要校验当前主题是否可以打卡
        var openid = app.globalData.logininfo.openid;
        if (openid != null && openid != "") {
          // 已登录
          util.post(api.fetchToken()).then(function (res) {
            if (res.access_token != '') {
              return Promise.resolve({
                access_token: res.access_token
              });
            }
          }).then(function (res) {
            var data = {};
            data.openid = openid;
            data.circleid = circleid;
            data.themeid = themeid;
            data.access_token = res.access_token;
            util.post(api.Interest_CheckUserThemeClockApi, data).then(function (res) {
              if (res.code == 200) {
                var result = res.result;
                var type = result.type;
                var message = result.message;
                if (type == 1) {
                  // 可以打卡
                  _this.submit();
                } else {
                  util.showToast(message, "none");
                }
              } else {
                util.showToast(res.message, "none");
              }
            })
          })
        }
      }else{
        _this.submit();
      }
    }
  },

  /**
   * 获取当前位置信息
   */
  getcurrentLocation: function(){
    var _this = this;
    wx.getLocation({
      type: 'wgs84',
      success(res) {
        var diaryPositionCurrent = {};
        diaryPositionCurrent.latitude = res.latitude;
        diaryPositionCurrent.longitude = res.longitude;
        _this.setData({
          diaryPositionCurrent: diaryPositionCurrent
        });
      }
    })
  },

  /**
   * 跳转到视频播放页面：日记
   */
  navigateToWebView: function (e) {
    var text = e.currentTarget.dataset.text;
    var type = e.currentTarget.dataset.type;
    if(type == 1){
      wx.navigateTo({
        url: '../../../../../../../pages/home/webView/webView?src=' + text,
      })
    }else{
      wx.openDocument({
        filePath: text,
        success: function (res) {
        }
      })
    }
  },

  /**
   * 链接底部弹出的选择
   */
  linkSelect: function (e) {
    var _this = this;
    _this.linkPopupClose();
    var type = e.currentTarget.dataset.type; 
    if(type == 1){
      // 粘贴公众号文章链接
      var diaryLink = _this.data.diaryLink;
      diaryLink.type = 1;
      diaryLink.name = "";
      diaryLink.ip = "";
      diaryLink.value = "";
      diaryLink.focus = true;
      diaryLink.isShow = true;
      diaryLink.textareaPlaceholderShow = true;
      diaryLink.state = "1";
      _this.setData({
        diaryLink: diaryLink
      })
    }else if(type == 2){
      // 从微信导入文件
      wx.chooseMessageFile({
        count: 1,
        type: 'file',
        success(res) {
          var tempFile = res.tempFiles[0];
          var path = tempFile.path;
          var pathIndex1 = path.lastIndexOf(".");
          var pathIndex2 = path.length;
          var suffix = path.substring(pathIndex1 + 1, pathIndex2);//后缀名
          if (suffix == "doc" || suffix == "docx" || suffix == "pdf" || suffix == "xlsx" || suffix == "xls" || suffix == "ppt" || suffix == "pptx"){
            var diaryLink = _this.data.diaryLink;
            diaryLink.type = 2;
            diaryLink.ip = "";
            diaryLink.name = tempFile.name;
            diaryLink.value = tempFile.path;
            diaryLink.size = tempFile.size;
            diaryLink.isShow = true;
            diaryLink.state = "2";
            _this.setData({
              diaryLink: diaryLink
            })
          }else{
            util.dialogAlert("请选择doc、docx、xls、ppt、pdf、xlsx、pptx格式的文件");
          }
        }
      })
    }
  },

  /**
   * 关闭链接的底部弹窗
   */
  linkPopupClose: function(){
    var _this = this;
    _this.setData({
      linkPopupShow: false,
      isOpenDiaShow: false
    })
  },
  
  /**
   * 预览图片
   */
  previewImage: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var diaryVideoAndImage = _this.data.diaryVideoAndImage;
    var urls = [];
    var current = diaryVideoAndImage[index].path;
    for (var i = 0; i < diaryVideoAndImage.length; i++) {
      if (diaryVideoAndImage[i].type == "1"){
        urls.push(diaryVideoAndImage[i].path);
      }
    }
    wx.previewImage({
      current: current, // 当前显示图片的http链接
      urls: urls // 需要预览的图片http链接列表
    })
  },

  /**
   * 跳转到视频播放页面：日记
   */
  navigateToVideo: function (e) {
    var _this = this;
    var src = e.currentTarget.dataset.src;
    wx.navigateTo({
      url: "../../../../../../../pages/home/video/video?id=&state=0&type=2&src=" + src 
    })
  },

  /**
   * 跳转到视频播放页面：圈子详情
   */
  navigateToVideoInterest: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var albumInfo = _this.data.albumInfo;
    var interestid = _this.data.ordInterest.id;
    var src = albumInfo[index].ip + albumInfo[index].videourl;
    wx.navigateTo({
      url: "../../../../../../../pages/home/video/video?state=1&type=1&id=" + interestid + "&src=" + src
    })
  },

  /**
   * 预览图片：圈子详情
   */
  previewImageInterest: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var albumInfo = _this.data.albumInfo;
    var urls = [];
    var current = albumInfo[index].ip + albumInfo[index].url;
    for (var i = 0; i < albumInfo.length; i++) {
      if (albumInfo[i].infoType == 2) {
        urls.push(albumInfo[i].ip + albumInfo[i].imageurl);
      }
    }
    wx.previewImage({
      current: current, // 当前显示图片的http链接
      urls: urls // 需要预览的图片http链接列表
    })
  },

  /**
   * 图片弹出层选择
   */
  imageSelect: function(e){
    var _this = this;
    var type = e.currentTarget.dataset.type;
    var diaryVideoAndImage = _this.data.diaryVideoAndImage;
    var diaryVideoAndImageThisSize = diaryVideoAndImage.length;
    var diaryVideoAndImageMaxSize = _this.data.diaryVideoAndImageMaxSize;
    var count = diaryVideoAndImageMaxSize - diaryVideoAndImageThisSize;
    if(type == 1){
      // 拍照
      wx.chooseImage({
        count: count,
        sizeType: ['original', 'compressed'],
        sourceType: ['camera'],
        success(res) {
          var tempFiles = res.tempFiles;
          for (var i = 0; i < tempFiles.length; i++) {
            var info = {};
            info.size = tempFiles[i].size;
            info.path = tempFiles[i].path;
            info.type = "1";
            info.state = "1";
            diaryVideoAndImage.push(info);
          }
          _this.setData({
            imagePopupShow: false,
            isOpenDiaShow: false,
            diaryVideoAndImage: diaryVideoAndImage
          });
        }
      })
    } else if (type == 2){
      // 从手机相册选择
      wx.chooseImage({
        count: count,
        sizeType: ['original', 'compressed'],
        sourceType: ['album'],
        success(res) {
          var tempFiles = res.tempFiles;
          for (var i = 0; i < tempFiles.length; i++) {
            var info = {};
            info.size = tempFiles[i].size;
            info.path = tempFiles[i].path;
            info.type = "1";
            info.state = "1";
            diaryVideoAndImage.push(info);
          }
          _this.setData({
            imagePopupShow: false,
            isOpenDiaShow: false,
            diaryVideoAndImage: diaryVideoAndImage
          });
        }
      })
    } else if(type == 3){
      //从微信导入图片
      wx.chooseMessageFile({
        count: count,
        type: 'image',
        success(res) {
          var tempFiles = res.tempFiles;
          for (var i = 0; i < tempFiles.length; i++) {
            var info = {};
            info.size = tempFiles[i].size;
            info.path = tempFiles[i].path;
            info.type = "1";
            info.state = "1";
            diaryVideoAndImage.push(info);
          }
          _this.setData({
            imagePopupShow: false,
            isOpenDiaShow: false,
            diaryVideoAndImage: diaryVideoAndImage
          });
        }
      })
    }
  },

  /**
   * 视频弹出层选择
   */
  videoSelect: function (e) {
    var _this = this;
    var type = e.currentTarget.dataset.type;
    var diaryVideoAndImage = _this.data.diaryVideoAndImage;
    var diaryVideoAndImageThisSize = diaryVideoAndImage.length;
    var diaryVideoAndImageMaxSize = _this.data.diaryVideoAndImageMaxSize;
    if (type == 1) {
      // 拍摄
      wx.chooseVideo({
        sourceType: ['camera'],
        maxDuration: util.getVideoFileMaxTime("diary"),
        camera: 'back',
        success(res) {
          var info = {};
          info.id = "myVideo" + new Date().getTime();
          info.size = res.size;
          info.path = res.tempFilePath;
          info.width = res.width;
          info.height = res.height;
          info.totalTime = res.duration;
          info.totalDate = util.digitalFormatTime(res.duration);
          info.type = "2";
          info.state = "1";
          diaryVideoAndImage.push(info);
          _this.setData({
            videoPopupShow: false,
            isOpenDiaShow: false,
            diaryVideoAndImage: diaryVideoAndImage,
            diaryVideoCount: 1
          })
        }
      })
    } else if (type == 2) {
      // 从手机相册选择
      wx.chooseVideo({
        sourceType: ['album'],
        maxDuration: util.getVideoFileMaxTime("diary"),
        camera: 'back',
        success(res) {
          var maxSize = util.getVideoFileMaxSize("diary");
          if ((res.size / 1024 / 1024) > maxSize) {
            util.dialogAlert("视频大小超出" + maxSize + "M");
            return;
          }

          var info = {};
          info.id = "myVideo" + new Date().getTime();
          info.size = res.size;
          info.path = res.tempFilePath;
          info.width = res.width;
          info.height = res.height;
          info.totalTime = res.duration;
          info.totalDate = util.digitalFormatTime(res.duration);
          info.type = "2";
          info.state = "1";
          diaryVideoAndImage.push(info);
          _this.setData({
            videoPopupShow: false,
            isOpenDiaShow: false,
            diaryVideoAndImage: diaryVideoAndImage,
            diaryVideoCount: 1
          })
        }
      })
    } else if (type == 3) {
      //从微信导入视频
      wx.chooseMessageFile({
        count: 1,
        type: 'video',
        success(res) {
          var tempFiles = res.tempFiles[0];
          var maxSize = util.getVideoFileMaxSize("diary");
          if ((tempFiles.size / 1024 / 1024) > maxSize){
            util.dialogAlert("视频大小超出" + maxSize + "M");
            return;
          }
          var info = {};
          info.id = "myVideo" + new Date().getTime();
          info.size = tempFiles.size;
          info.path = tempFiles.path;
          info.width = 0;
          info.height = 0;
          info.totalTime = 0;
          info.totalDate = "00:00";
          info.type = "2";
          info.state = "1";
          diaryVideoAndImage.push(info);
          _this.setData({
            videoPopupShow: false,
            isOpenDiaShow: false,
            diaryVideoAndImage: diaryVideoAndImage,
            diaryVideoCount: 1
          });
        }
      })
    }
  },

  /**
   * 关闭图片弹出层
   */
  imagePopupClose: function () {
    var _this = this;
    _this.setData({
      imagePopupShow: false,
      isOpenDiaShow: false
    })
  },

  /**
   * 关闭视频弹出层
   */
  videoPopupClose: function () {
    var _this = this;
    _this.setData({
      videoPopupShow: false,
      isOpenDiaShow: false
    })
  },

  /**
   * 语音拒绝授权的提示弹窗关闭
   */
  audioOauhRefusedDialogClose: function () {
    var _this = this;
    _this.setData({
      audioOauhRefusedDialogShow: false
    })
  },

  /**
   * 语音拒绝授权的提示弹窗确认动作
   */
  audioOauhRefusedDialogSuccess: function () {
    var _this = this;
    wx.openSetting({
      success: function (data) {
        if (data.authSetting["scope.record"] == true) {
          // 授权成功
          _this.audioOauhRefusedDialogClose();
        } else {
          // 授权失败
          _this.audioOauhRefusedDialogClose();
        }
      }
    })
  },

  /**
   * 语音拒绝授权的提示弹窗关闭
   */
  addressOauhRefusedDialogClose: function () {
    var _this = this;
    _this.setData({
      addressOauhRefusedDialogShow: false
    })
  },

  /**
   * 语音拒绝授权的提示弹窗确认动作
   */
  addressOauhRefusedDialogSuccess: function () {
    var _this = this;
    wx.openSetting({
      success: function (data) {
        if (data.authSetting["scope.userLocation"] == true) {
          // 授权成功
          _this.addressOauhRefusedDialogClose();
        } else {
          // 授权失败
          _this.addressOauhRefusedDialogClose();
        }
      }
    })
  },

  /**
   * 关闭赞赏提示
   */
  zsDialogShow: function(){
    var _this = this;
    _this.setData({
      zsDialogShow: !_this.data.zsDialogShow
    })
    if(!_this.data.zsDialogShow){
      _this.setData({
        zsDialogAs: false
      })
    }
  },


  /**
   * 获取主题信息
   */
  getThemeInfoBySelect: function () {
    var _this = this;
    var themeid = _this.data.themeid;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.themeid = themeid;
        data.access_token = res.access_token;
        util.post(api.Interest_GetThemeInfoBySelectApi, data).then(res => {
          if (res.code == 200) {
            var isCheckCompleteByDiary = res.result.isCheckCompleteByDiary;
            var dataInfoList = res.result.dataInfoList;
            for (var i = 0; i < dataInfoList.length; i++) {
              var dataInfo = dataInfoList[i];
              switch (dataInfo.type) {
                case 3:
                  dataInfo.startDate = "00:00";
                  dataInfo.voiceBoFangImage = api.AudioNoBoFangImage_Name;
                  dataInfo.currentTime = 0;
                  break;
                case 4:
                  var videoid = "myVideo" + new Date().getTime() + i;
                  dataInfo.videoid = videoid;
                  break;
              }
              dataInfoList[i] = dataInfo;
              _this.setData({
                themeInfo: res.result.ordTheme,
                themeDataList: dataInfoList,
                isCheckCompleteByDiary: isCheckCompleteByDiary
              })
            }
          }
        })
      })
    }
  },
})